package com.ch3cooh.proxy;

import com.ch3cooh.proxy.core.impl.JdkProxy;
import org.springframework.beans.factory.FactoryBean;

/**
 * @功能: 代理工厂bean,在getObject()处负责使用ProxyUtil创建代理对象
 * @作者:chanson
 * @时间:2018/5/1 22:45
 */
public class ProxyFactory<T> implements FactoryBean<T> {

    private Class<T> interfaceClass;

    public Class<T> getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    @Override
    public T getObject() throws Exception {
     //   return (T) new ProxyObject().bind(interfaceClass);
        return (T)new JdkProxy(interfaceClass).createProxy();
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceClass;
    }

    @Override
    public boolean isSingleton() {
        // 单例模式
        return true;
    }

}
